package com.linln.wxapi;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.linln.common.utils.ResultVoUtil;
import com.linln.common.vo.ResultVo;
import com.linln.modules.member.domain.AreaCount;
import com.linln.modules.member.service.AreaCountService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 商户相关小程序接口
 * @author hct
 *
 */
@Api(value="统计信息管理")
@RestController
@RequestMapping("/wx/area/{area}")
public class WxApiAreaCountController {
	
	  @Autowired
	  private AreaCountService areaCountService;
	 
	  
    private final Logger logger = LoggerFactory.getLogger(this.getClass());
   
   /**
     * 获取商户分类信息
     * @param appid
     * @param code
     * @return
     */
     @ApiOperation(value = "获取统计信息",  notes = "获取统计信息")
     @RequestMapping(value = "info",method={RequestMethod.POST,RequestMethod.GET})
     @ResponseBody
     public ResultVo areacountinfo(@PathVariable String area) {
        
         try {
        	 logger.info("area===="+area);
         	// 创建匹配器，进行动态查询匹配
              AreaCount areacount = areaCountService.findByArea(area);
              if(areacount==null) {
            	  areacount=new AreaCount();
            	  areacount.setMessage_fabunum(0);
            	  areacount.setMessage_shouFabunum(325319);
            	  areacount.setMessage_readnum(0);
            	  areacount.setMessage_shouReadnum(315672);               	  
              }else {
            	  if(areacount.getMessage_fabunum()==null) {
                	  areacount.setMessage_fabunum(0);
            	  }
            	  if(areacount.getMessage_readnum()==null) {
                	  areacount.setMessage_readnum(0);
            	  }
            	  if(areacount.getMessage_shouFabunum()==null) {
                	  areacount.setMessage_shouFabunum(22312);
            	  }
            	  if(areacount.getMessage_shouReadnum()==null) {
                	  areacount.setMessage_shouReadnum(1212212);
            	  }
              }
              areacount.setMessage_fabunum(areacount.getMessage_fabunum()+areacount.getMessage_shouFabunum());
              areacount.setMessage_readnum(areacount.getMessage_readnum()+areacount.getMessage_shouReadnum());
             return ResultVoUtil.success(areacount);
         } catch (Exception e) {
             this.logger.error(e.getMessage(), e);
             return ResultVoUtil.error("接口异常"); 
         }
     }
    
    
}

    

